package com.ruoyi.active.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.active.domain.TbProdAtta;
import com.ruoyi.active.service.ITbProdAttaService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品附件Controller
 * 
 * @author ruoyi
 * @date 2025-08-01
 */
@RestController
@RequestMapping("/atta")
public class TbProdAttaController extends BaseController
{
    @Autowired
    private ITbProdAttaService tbProdAttaService;

    /**
     * 查询商品附件列表
     */
    @RequiresPermissions("active:atta:list")
    @GetMapping("/list")
    public TableDataInfo list(TbProdAtta tbProdAtta)
    {
        startPage();
        List<TbProdAtta> list = tbProdAttaService.selectTbProdAttaList(tbProdAtta);
        return getDataTable(list);
    }

    /**
     * 导出商品附件列表
     */
    @RequiresPermissions("active:atta:export")
    @Log(title = "商品附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbProdAtta tbProdAtta)
    {
        List<TbProdAtta> list = tbProdAttaService.selectTbProdAttaList(tbProdAtta);
        ExcelUtil<TbProdAtta> util = new ExcelUtil<TbProdAtta>(TbProdAtta.class);
        util.exportExcel(response, list, "商品附件数据");
    }

    /**
     * 获取商品附件详细信息
     */
    @RequiresPermissions("active:atta:query")
    @GetMapping(value = "/{attaId}")
    public AjaxResult getInfo(@PathVariable("attaId") Long attaId)
    {
        return success(tbProdAttaService.selectTbProdAttaByAttaId(attaId));
    }

    /**
     * 新增商品附件
     */
    @RequiresPermissions("active:atta:add")
    @Log(title = "商品附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbProdAtta tbProdAtta)
    {
        return toAjax(tbProdAttaService.insertTbProdAtta(tbProdAtta));
    }

    /**
     * 修改商品附件
     */
    @RequiresPermissions("active:atta:edit")
    @Log(title = "商品附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbProdAtta tbProdAtta)
    {
        return toAjax(tbProdAttaService.updateTbProdAtta(tbProdAtta));
    }

    /**
     * 删除商品附件
     */
    @RequiresPermissions("active:atta:remove")
    @Log(title = "商品附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attaIds}")
    public AjaxResult remove(@PathVariable Long[] attaIds)
    {
        return toAjax(tbProdAttaService.deleteTbProdAttaByAttaIds(attaIds));
    }
}
